package shajie.shajun.mmhf.View.Fragment;

import android.text.TextUtils;
import android.view.View;

import Util.RegexUtil;
import shajie.shajun.mmhf.Base.BaseFragment;
import shajie.shajun.mmhf.Bean.User2;
import shajie.shajun.mmhf.R;
import shajie.shajun.mmhf.databinding.FragmentRegisterBinding;

/**
 * Created by Administrator on 2017/11/3.
 */

public class Register_Fragment extends BaseFragment<FragmentRegisterBinding> implements View.OnClickListener{
    private FragmentRegisterBinding binding;
   // private User user;
    private User2 user2;
    @Override
    public int setlayoutid() {
        return R.layout.fragment_register;
    }
    @Override
    public void init(FragmentRegisterBinding bingding) {
        binding=bingding;
       // user=new User();
        user2=new User2();
        bingding.setUser(user2);
        bingding.setOnclicklistener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.register:
                register();
                break;
            case R.id.back_register:
                getFragmentManager().popBackStack();
                break;
        }
    }

    public void register(){
        if (binding.loginPhone.getText().toString().length()!=11){
            toast("手机号有误");
            return;
        }
       if (TextUtils.isEmpty(binding.loginNumber.getText())){
            toast("职位不能为空");
            return;
        }
        if (!RegexUtil.checkname(binding.loginName.getText().toString())){
            toast("姓名不符合要求");
            return;
        }
        if (!(RegexUtil.checkInputchart(binding.loginName2.getText().toString()) && binding.loginName2.length()>2 && binding.loginName2.length()<14)){
            toast("账号不符合要求");
            return;
        }
        if (!binding.loginPassword0.getText().toString().equals(binding.loginPassword1.getText().toString())){
            toast("两次密码输入不一致");
            return;
        }
        if (!RegexUtil.checkpassword6_20(binding.loginPassword0.getText().toString())){
            toast("密码不符合要求!!");
            return;
        }
//        user.setUsername(user2.getUsername());
//        user.setPassword(user2.getPassword());
//        user.setMobilePhoneNumber(user2.getMobilePhoneNumber());
//        user.setJob(user2.getJob());
//        user.setAccount(user2.getAccount());
//        if (Util.checknetwork(getContext())) {
//            user.signUpObservable(User.class)
//                    .subscribe(new Action1<User>() {
//                        @Override
//                        public void call(User user) {
//                           // startActivity(new Intent(mContext, MainActivity.class));
//                            toast("注册成功！");
//                            Public p2 = new Public();
//                            p2.setTitle(user.getAccount());
//                            p2.setContent("暂无");
//                            p2.save(new SaveListener<String>() {
//                                @Override
//                                public void done(String objectId,BmobException e) {
//                                    if(e==null){
//                                       // toast("添加数据成功，返回objectId为："+objectId);
//                                    }else{
//                                        toast("创建数据失败：" + e.getMessage());
//                                    }
//                                }
//                            });
//                            getFragmentManager().popBackStack();
//                        }
//                    }, new Action1<Throwable>() {
//                        @Override
//                        public void call(Throwable throwable) {
//                            toast("注册异常：" + throwable.getMessage());
//                        }
//                    });

//        }

    }
}
